package psn.kiko.controller.navigation;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import psn.kiko.annotation.api.StableID;
import psn.kiko.pojo.PageResult;
import psn.kiko.pojo.Result;
import psn.kiko.pojo.dto.NavigationDTO;
import psn.kiko.pojo.vo.DelDetailVO;
import psn.kiko.pojo.vo.LabelValue;
import psn.kiko.pojo.vo.NavigationVO;
import psn.kiko.pojo.vo.SimpleIconFontVO;
import psn.kiko.service.business.system.NavigationService;

import java.util.List;

/**
 * 导航管理接口
 */
@RestController
@RequestMapping("/admin/navigation")
@Api(tags = {"导航管理"})
public class NavigationController{
	@Autowired
	NavigationService navigationService;
	
	@PostMapping("/pagingGetWithCondition/{pageNum}/{pageSize}")
	@ApiOperation("携带条件地分页获取导航集合")
	@StableID(301)
	public Result pagingGetWithCondition(
			@PathVariable("pageNum") @ApiParam("页码") int pageNum,
			@PathVariable("pageSize") @ApiParam("页面尺寸") int pageSize,
			@RequestBody @ApiParam("导航DTO") NavigationDTO navigationDTO
	){
		PageResult pageResult = navigationService.pagingWithCondition(navigationDTO,pageNum,pageSize);
		return Result.success(pageResult);
	}
	
	@GetMapping("/{navId}")
	@ApiOperation("获取所有携带说明的导航类型")
	@StableID(302)
	public Result getByNavId(@PathVariable("navId") @ApiParam("导航主键") Integer navId){
		NavigationVO navigationVO = navigationService.getNavigationById(navId);
		return Result.success(navigationVO);
	}
	
	@GetMapping("getAllNavTypes")
	@ApiOperation("获取所有携带说明的导航类型")
	@StableID(303)
	public Result getAllNavTypes(){
		List<LabelValue> navigationTypes = navigationService.getNavTypesWithLabel();
		return Result.success(navigationTypes);
	}
	
	@GetMapping("/getAllNavEnables")
	@ApiOperation("获取携带说明的状态值")
	@StableID(304)
	public Result getAllNavEnables(){
		List<LabelValue> statuses = navigationService.getStatusesWithLabel();
		return Result.success(statuses);
	}
	
	@PostMapping("/add")
	@ApiOperation("添加导航")
	@StableID(305)
	public Result batchAdd(@RequestBody @ApiParam("导航DTO") NavigationDTO navigationDTO){
		Integer r = navigationService.addNavigation(navigationDTO);
		return Result.success(r);
	}
	
	@DeleteMapping("/batchDeleteByIds")
	@ApiOperation("根据主键批量删除导航")
	@StableID(306)
	public Result batchDeleteByIds(@RequestBody @ApiParam("导航主键集合") List<Integer> ids){
		List<DelDetailVO> delDetailVOS = navigationService.deleteNavByIds(ids);
		return Result.success(delDetailVOS);
	}
	
	@PutMapping("/updateNavigation")
	@ApiOperation("修改导航信息")
	@StableID(307)
	public Result updateNavigation(@RequestBody @ApiParam("导航DTO") NavigationDTO navigationDTO){
		Integer r = navigationService.updateNav(navigationDTO);
		return Result.success(r);
	}
	
	@GetMapping("/allNavGroups")
	@ApiOperation("获取所有导航组")
	@StableID(308)
	public Result allNavGroups(){
		List<NavigationVO> navGroups = navigationService.getALlNavGroups();
		return Result.success(navGroups);
	}
	
	@PutMapping("/batchEnableNav")
	@ApiOperation("批量启用一批导航")
	@StableID(309)
	public Result batchEnableNav(@RequestBody @ApiParam("导航id集合") List<Integer> navIds){
		Integer r = navigationService.batchEnableNavByIds(navIds);
		return Result.success(r);
	}
	
	@PutMapping("/batchDisableNav")
	@ApiOperation("批量禁用一批导航")
	@StableID(310)
	public Result batchDisableNav(@RequestBody @ApiParam("导航id集合") List<Integer> navIds){
		Integer r = navigationService.batchDisableNavByIds(navIds);
		return Result.success(r);
	}
	
	@GetMapping("/navItemsOfNavGroup/{navGroupId}/{pageNUm}/{pageSize}")
	@ApiOperation("获取某一导航组的所有导航项")
	@StableID(311)
	public Result navItemsOfNavGroup(
			@PathVariable("navGroupId") @ApiParam("导航组id") Integer navGroupId,
			@PathVariable("pageNUm") @ApiParam("页码") Integer pageNUm,
			@PathVariable("pageSize") @ApiParam("页面大小") Integer pageSize
	){
		PageResult<Object> pageResult = navigationService.geAllNavItemsOfNavGroup(navGroupId,pageNUm,pageSize);
		return Result.success(pageResult);
	}
	
	
	@PutMapping("/batchRemoveItemsOfNavGroup")
	@ApiOperation("移除导航组的一批导航项")
	@StableID(312)
	public Result batchRemoveItemsOfNavGroup(
			@RequestBody @ApiParam("导航项id集合") List<Integer> navItemIds){
		Integer r = navigationService.batchRemoveItemsOfNavGroup(navItemIds);
		return Result.success(r);
	}
	
	@PutMapping("/batchAllocateItemsToNavGroup/{navGroupId}")
	@ApiOperation("给导航组添加一批导航项")
	@StableID(313)
	public Result batchAllocateItemsToNavGroup(
			@PathVariable("navGroupId") @ApiParam("导航组id") Integer navGroupId,
			@RequestBody @ApiParam("导航项id集合") List<Integer> navItemIds){
		Integer r = navigationService.batchAllocateItemsToNavGroup(navGroupId,navItemIds);
		return Result.success(r);
	}
	
	@PutMapping("/batchEnableItemsOfNavGroup/{navGroupId}")
	@ApiOperation("启用导航组的一批导航项")
	@StableID(314)
	public Result batchEnableItemsOfNavGroup(
			@PathVariable("navGroupId") @ApiParam("导航组id") Integer navGroupId,
			@RequestBody @ApiParam("导航项id集合") List<Integer> navItemIds){
		Integer r = navigationService.batchEnableItemsOfNavGroup(navGroupId,navItemIds);
		return Result.success(r);
	}
	
	@PutMapping("/batchDisableItemsOfNavGroup/{navGroupId}")
	@ApiOperation("禁用导航组的一批导航项")
	@StableID(315)
	public Result batchDisableItemsOfNavGroup(
			@PathVariable("navGroupId") @ApiParam("导航组id") Integer navGroupId,
			@RequestBody @ApiParam("导航项id集合") List<Integer> navItemIds){
		Integer r = navigationService.batchDisableItemsOfNavGroup(navGroupId,navItemIds);
		return Result.success(r);
	}
	
	@GetMapping("/unAllocatedItems/{pageNum}/{pageSize}")
	@ApiOperation("获取未分配的导航项")
	@StableID(316)
	public Result unAllocatedItems(
			@PathVariable("pageNum") @ApiParam("页码") int pageNUm,
			@PathVariable("pageSize") @ApiParam("页面大小") int pageSize
	){
		PageResult<Object> pageResult = navigationService.unAllocatedItems(pageNUm,pageSize);
		return Result.success(pageResult);
	}
	
	@GetMapping("/getIconSelect")
	@ApiOperation("获取图标选项")
	@StableID(317)
	public Result getIconSelect(){
		List<SimpleIconFontVO> simpleIconFontVOS = navigationService.getIconSelect();
		return Result.success(simpleIconFontVOS);
	}
}
